////////////////////////////////////////////////////////////////////////////////
// Copyright 2006 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   CODE
// AUTHOR           :   Saint Peng 
// DATE CREATE      :   2006/01/05
// DESCRIPTION      :   a BIZ LOGIC file for the function, CODE
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2006/01/05   Saint Peng      1.0                 source is generated.
//
//
//
////////////////////////////////////////////////////////////////////////////////

package com.erp.app.setup.codeSetup.bizLogic;

import java.sql.Connection;
import java.util.ArrayList;

import com.erp.app.common.util.ProjectDbObjectUtil;
import com.erp.app.setup.codeSetup.vo.CodeHdrVo;
import com.erp.framework.model.bizLogic.SimpleSearchMaintStyleBizLogic;
import com.erp.framework.model.vo.SimpleBaseVo;
import com.erp.framework.util.logger.Logger;

/**
* <p>A <strong>BizLogic</strong> provides the logical flow and control
* of the business model at different transaction time.
*
* @author          Saint Peng 
* @version 1.0     2006/01/05
* @since           FrameWork 1.0
*
*/
public class CodeBizLogic extends SimpleSearchMaintStyleBizLogic {

	/**
	* Generates a unique document number.
	*
	* @param      model   the incoming business model (VO)
	* @param      conn    the database connection
	*
	* @author     Saint Peng 
	* @since      FrameWork 1.0
	*/
	public void genDocNo(SimpleBaseVo model, Connection conn) throws Exception {

	}

	/**
	* Provides logics to insert business object before creating the object.
	* Note that this function has NO user transaction control.
	*
	* @param      model   the incoming business model (VO)
	*
	* @author     Saint Peng 
	* @since      FrameWork 1.0
	*/
	public void bizLogicsBeforeCreate(SimpleBaseVo model) throws Exception {
		Logger.debug(this, "in bizLogicsBeforeCreate()");
	}

	/**
	* Provides logics to insert business object before creating the object.
	* Note that this function has user transaction control.
	*
	* @param      model   the incoming business model (VO)
	* @param      conn    the database connection
	*
	* @author     Saint Peng 
	* @since      FrameWork 1.0
	*/
	public void bizLogicsBeforeCreateModel(SimpleBaseVo model, Connection conn) throws Exception {

		Logger.debug(this, "in bizLogicsBeforeCreateModel()");
	}

	/**
	* Provides logics to insert business object after creating the object.
	* Note that this function has user transaction control.
	*
	* @param      model   the incoming business model (VO)
	* @param      conn    the database connection
	*
	* @author     Saint Peng 
	* @since      FrameWork 1.0
	*/
	public void bizLogicsAfterCreateModel(SimpleBaseVo model, Connection conn) throws Exception {

		Logger.debug(this, "in bizLogicsAfterCreateModel()");

		// syn other companies' record
		updateMasterRecord(model, conn);
	}
	
	/**
	* Provides logics to insert business object after creating the object.
	* Note that this function has NO user transaction control.
	*
	* @param      model   the incoming business model (VO)
	*
	* @author     Saint Peng 
	* @since      FrameWork 1.0
	*/
	public void bizLogicsAfterCreate(SimpleBaseVo model) throws Exception {

		Logger.debug(this, "in bizLogicsAfterCreate()");
	}

	/**
	* Provides logics to update business object before updating the object.
	* Note that this function has NO user transaction control.
	*
	* @param      model   the incoming business model (VO)
	*
	* @author     Saint Peng 
	* @since      FrameWork 1.0
	*/
	public void bizLogicsBeforeUpdate(SimpleBaseVo model) throws Exception {

		Logger.debug(this, "in bizLogicsBeforeUpdate()");
	}
	
	/**
	* Provides logics to update business object before updating the object.
	* Note that this function has user transaction control.
	*
	* @param      model   the incoming business model (VO)
	* @param      conn    the database connection
	*
	* @author     Saint Peng 
	* @since      FrameWork 1.0
	*/
	public void bizLogicsBeforeUpdateModel(SimpleBaseVo model, Connection conn) throws Exception {

		Logger.debug(this, "in bizLogicsBeforeUpdateModel()");
	}

	/**
	* Provides logics to update business object after updating the object.
	* Note that this function has user transaction control.
	*
	* @param      model   the incoming business model (VO)
	* @param      conn    the database connection
	*
	* @author     Saint Peng 
	* @since      FrameWork 1.0
	*/
	public void bizLogicsAfterUpdateModel(SimpleBaseVo model, Connection conn) throws Exception {

		Logger.debug(this, "in bizLogicsAfterUpdateModel()");

		// syn other companies' record
		updateMasterRecord(model, conn);
	}

	/**
	* Provides logics to update business object after updating the object.
	* Note that this function has NO user transaction control.
	*
	* @param      model   the incoming business model (VO)
	*
	* @author     Saint Peng 
	* @since      FrameWork 1.0
	*/
	public void bizLogicsAfterUpdate(SimpleBaseVo model) throws Exception {

		Logger.debug(this, "in bizLogicsAfterUpdate()");
	}
	
	/**
	* Provides logics to remove business object before removing the object.
	* Note that this function has NO user transaction control.
	*
	* @param      model   the incoming business model (VO)
	*
	* @author     Saint Peng 
	* @since      FrameWork 1.0
	*/
	public void bizLogicsBeforeRemove(SimpleBaseVo model) throws Exception {

		Logger.debug(this, "in bizLogicsBeforeRemove()");
	}
	
	/**
	* Provides logics to remove business object before removing the object.
	* Note that this function has user transaction control.
	*
	* @param      model   the incoming business model (VO)
	* @param      conn    the database connection
	*
	* @author     Saint Peng 
	* @since      FrameWork 1.0
	*/
	public void bizLogicsBeforeRemoveModel(SimpleBaseVo model, Connection conn) throws Exception {

		Logger.debug(this, "in bizLogicsBeforeRemoveModel()");
	}

	/**
	* Provides logics to remove business object after removing the object.
	* Note that this function has user transaction control.
	*
	* @param      model   the incoming business model (VO)
	* @param      conn    the database connection
	*
	* @author     Saint Peng 
	* @since      FrameWork 1.0
	*/
	public void bizLogicsAfterRemoveModel(SimpleBaseVo model, Connection conn) throws Exception {

		Logger.debug(this, "in bizLogicsAfterRemoveModel()");

		// syn other companies' record
		updateMasterRecord(model, conn);
	}
	/**
	* Provides logics to remove business object after removing the object.
	* Note that this function has NO user transaction control.
	*
	* @param      model   the incoming business model (VO)
	*
	* @author     Saint Peng 
	* @since      FrameWork 1.0
	*/
	public void bizLogicsAfterRemove(SimpleBaseVo model) throws Exception {

		Logger.debug(this, "in bizLogicsAfterRemove()");
	}

	// syn other companies' record if this master share among companies
	public void updateMasterRecord(SimpleBaseVo model, Connection conn) throws Exception {
		ProjectDbObjectUtil dbUtil = new ProjectDbObjectUtil();
		CodeHdrVo vo = (CodeHdrVo) model;
		String spName = "SP_UPD_MST_CODE";
		
		ArrayList args = new ArrayList();
		args.add(vo.getCompanyCode()); // in_company_code
		args.add(vo.getRefMasterCode()); // in_type
		args.add(vo.getRefMasterCode()); // in_code
		dbUtil.callSp(spName, args, conn);
	}	
}
